<template>
  <div class="suggest-main-box">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="内容">
        <div class="suggest-content"  v-html="form.content"></div>
      </el-form-item>
      <el-form-item label="附件" prop="attachment">
        <file-upload v-model="form.attachment" :isShowTip="false"/>
      </el-form-item>
      <el-form-item label="提交人" prop="userName">
        {{form.userName}}
      </el-form-item>
      <el-form-item label="是否匿名" prop="isAnonymity">
        <el-checkbox v-model="form.isAnonymity ? true: false" disabled></el-checkbox>
      </el-form-item>
      <el-form-item label="回复内容" prop="replyResult">
        <editor v-model="form.replyResult" :min-height="192"/>
      </el-form-item>
      <el-form-item label="是否公示" prop="isPublish">
        <el-checkbox v-model="form.isPublish"></el-checkbox>
      </el-form-item>
      <el-form-item label="是否置顶" prop="isTop">
        <el-checkbox v-model="form.isTop"></el-checkbox>
      </el-form-item>
      <el-form-item label="处理状态" prop="status">
        {{form.status  == 1 ? '已处理' : '未处理'}}
      </el-form-item>
      <el-form-item label="处理人" prop="replyUserName" v-if="form.replyUserName">
        {{form.replyUserName}}
      </el-form-item>
      <el-form-item label="处理时间" prop="replyTime" v-if="form.replyTime">
        {{form.replyTime}}
      </el-form-item>
    </el-form>
    <div class="footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
    import {getSuggest,updateSuggest } from "@/api/examine/suggest";
    import {formatDate} from "../../../utils";
    export default {
        name: "detail",
        data(){
          return {
            form:{
              id: '',
              content: '',
              attachment: '/profile/upload/2023/08/01/20230801104607A004/个人激励排名 (14).xlsx',
              isAnonymity: 1,
              replyResult: '',
              isPublish: false,
              isTop:false
            }
          }
        },
        methods:{
          submitForm(){
            if(this.form.replyResult == '<p><br></p>'){
                this.form.replyResult = ''
            }
            let param ={
              id:this.form.id,
              replyResult :  this.form.replyResult ? encodeURIComponent(this.form.replyResult) : '',
              isPublish: this.form.isPublish ? 1 : 0,
              isTop: this.form.isTop ? 1: 0
            }
            updateSuggest(param).then(res=>{
              this.$modal.msgSuccess("提交成功");
              this.$router.push({path: "/suggest/suggest"});
            })
          },
          getDetail(){
            getSuggest(this.form.id).then(res=>{
              if(res.code == 200){
                this.form = res.data
                this.form.replyTime = formatDate(new Date(this.form.replyTime).getTime())
                this.form.isPublish = this.form.isPublish == 1 ? true :false
                this.form.isTop = this.form.isTop == 1 ? true :false
              }
            })
          },
          cancel(){
            this.$router.push({path: "/suggest/suggest"});
          }
        },
        created() {
          if(this.$route.query.id){
            this.form.id = this.$route.query.id
            this.getDetail()
          }
        }

    }
</script>

<style scoped lang="scss">
  .suggest-main-box{
    padding: 30px 0;
    width: 80%;
    margin-left: 9%;
    ::v-deep{
      .upload-file-uploader{
        display: none;
      }
      .el-link--inner{
        color: rgb(64, 158, 255);;
      }
      .el-upload-list__item{
        padding: 0 10px;
      }
    }
    .footer{
      text-align: center;
    }
    .suggest-content{
      line-height: 1.5;
      padding-top: 10px;
    }
  }
</style>
